package com.qinglei.recoup.system.manager.adapter.impl;


import com.alibaba.fastjson.JSON;
import com.qinglei.recoup.common.domain.RadarMessage;
import com.qinglei.recoup.common.exception.RedisConnectException;
import com.qinglei.recoup.system.manager.BreathHeartAlarmV4;
import com.qinglei.recoup.system.manager.adapter.RadarVersionAdapter;
import com.qinglei.recoup.system.service.BedService;
import com.qinglei.recoup.system.service.RadarService;
import com.qinglei.recoup.system.service.RadarUserDataFourService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: 最爱学英语的cxd
 * @slogan: 一入代码深似海，从此红尘是路人
 * @create: 2022-05-05
 **/
@Slf4j
@Service
public class RadarV4Adapter implements RadarVersionAdapter {

    @Resource
    private RadarUserDataFourService radarUserDataFourService;

    @Resource
    private RadarService radarService;

    @Resource
    private BedService bedService;

    @Resource
    private BreathHeartAlarmV4 breathHeartAlarmV4;


    @Override
    public void handleDRadarData(RadarMessage message) {
        try {
            radarUserDataFourService.saveRadarUserData(message);
        } catch (MQBrokerException e) {
            e.printStackTrace();
        } catch (RemotingException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (MQClientException e) {
            e.printStackTrace();
        } catch (RedisConnectException e) {
            e.printStackTrace();
        }
        radarService.updateOnlineStatus(message.getSn());
        radarService.updateNetworkStatus(message.getSn());
        bedService.procRadarDataV4(message);
        breathHeartAlarmV4.updateBreathStatus(message);

    }
}
